package com.daodaofun.weibo.service.impl;

import com.daodaofun.util.StringUtil;
import com.daodaofun.weibo.mapper.PostMapper;
import com.daodaofun.weibo.model.Post;
import com.daodaofun.weibo.model.PostInfo;
import com.daodaofun.weibo.service.PostService;
import com.daodaofun.weibo.service.UserService;
import javafx.geometry.Pos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PostServiceImpl implements PostService {

    @Autowired
    private PostMapper postMapper;

    @Autowired
    private UserService userService;

    @Override
    public void save(Post post) {
        post.setCreateTime(new Date());
        post.setPostId(StringUtil.uuid());

        postMapper.insert(post);
    }

    @Override
    public List<PostInfo> listCurrentPosts(Long userId) {
        // 要确定我关注了哪些人
        List<Long> masters = userService.findMasters(userId);

        masters.add(userId);
        List<PostInfo> posts = postMapper.findByUserIds(masters);

        return posts;
    }
}
